﻿using System;
using System.Windows;
using System.Windows.Controls;
using Infragistics.Composite.Wpf.Proxies.Docking;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Infragistics.Composite.Wpf.Proxies.Tests.Docking
{
    /// <summary>
    /// Unit tests for the SplitPaneProxy class.
    /// </summary>
    [TestClass]
    public class SplitPaneProxyTests
    {
        #region Boilerplate Code

        public SplitPaneProxyTests()
        {
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        #endregion // Boilerplate Code

        const string PANE_NAME = "TestPane";

        [TestMethod]
        public void TestAddContentPaneProxy()
        {
            SplitPaneProxy target = new SplitPaneProxy(PANE_NAME);

            ContentPaneProxy contentPaneProxy = new ContentPaneProxy("foo");
            target.AddContentPaneProxy(contentPaneProxy, false);

            Assert.AreEqual(0, target.TabGroupPaneProxy.TabGroupPane.Items.Count);
            Assert.AreEqual(contentPaneProxy.ContentPane, target.SplitPane.Panes[0]);
        }

        [TestMethod]
        public void TestAddContentPaneProxyInTabGroup()
        {
            SplitPaneProxy target = new SplitPaneProxy(PANE_NAME);

            ContentPaneProxy contentPaneProxy = new ContentPaneProxy("foo");
            target.AddContentPaneProxy(contentPaneProxy, true);

            Assert.AreEqual(target.TabGroupPaneProxy.TabGroupPane.Items[0], contentPaneProxy.ContentPane);
        }

        [TestMethod]
        public void TestProxiedProperties()
        {
            SplitPaneProxy target = new SplitPaneProxy(PANE_NAME);

            Assert.IsTrue(VerifyPropertyValue(target, SplitPaneProxy.SplitterOrientationProperty, Orientation.Horizontal), "SplitterOrientation");
        }

        bool VerifyPropertyValue(SplitPaneProxy target, DependencyProperty property, object value)
        {
            Style style = new Style(typeof(SplitPaneProxy));
            style.Setters.Add(new Setter(property, value));
            target.Style = style;

            object actualValue = target.SplitPane.GetValue(property);
            return Object.Equals(value, actualValue);
        }
    }
}